﻿package Net::FTP::Client::Listing::System::DOS;

use JIP::ToolSet; # load my commonly-used modules in a single import
use parent qw( Net::FTP::Client::Listing );
use Readonly qw( Readonly );
use English qw( -no_match_vars );

# 02-05-96  10:48AM                 1415 src.slf
# 09-10-96  09:18AM       <DIR>          sl_util
Readonly my $REGEX => qr/^\d\d-\d\d-\d\d\s+\d\d:\d\d\wM # Date and time info
                        \s+                             # Some space
                        (<\w{3}>|\d+)                   # Dir or Size
                        \s+                             # Some more space
                        (.+)$                           # File name
                        /x;

sub parseDir {
    my $self = shift;

    my @listing;

    foreach ( @ARG ) {
        my %desc; # file description

        if ( ( $desc{'sizeOrDir'}, $desc{'name'} ) = $ARG =~ $REGEX ) {
            if ( $desc{'sizeOrDir'} ne '<DIR>' ) {
                $desc{'type'} = 'f';
                $desc{'size'} = $desc{'sizeOrDir'};
            }
            else {
                next if $desc{'name'} eq '.' or $desc{'name'} eq '..';

                $desc{'type'} = 'd';
                $desc{'size'} = undef;
            }

            delete $desc{'sizeOrDir'};

            push( @listing, \%desc );
        }
    }

    return @listing;
}

1;
